package com.林子祺.全名健康管理系统.view.servlet.content.communicate;

import com.林子祺.全名健康管理系统.controller.content.communicate.Comm;
import com.林子祺.全名健康管理系统.entity.article.content.communicate.CommData;
import com.林子祺.全名健康管理系统.entity.article.content.communicate.CurrentCommData;
import com.林子祺.全名健康管理系统.util.AskStructure;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

//转发
@WebServlet("/DispachAnswered")
public class DispachAnswered extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");

        String user = (String) req.getSession().getAttribute("user");

        CommData.Refresh();
        Comm.user(user);

        List i = new ArrayList();
        List not = new ArrayList();
        int number = 0;
        while(CommData.OutputCommData(number)){
            if(CurrentCommData.response == 0)
                i.add(new AskStructure(CurrentCommData.id,CurrentCommData.name,CurrentCommData.ask,CurrentCommData.askperson,CurrentCommData.response,CurrentCommData.anstext));
            else
                not.add(new AskStructure(CurrentCommData.id,CurrentCommData.name,CurrentCommData.ask,CurrentCommData.askperson,CurrentCommData.response,CurrentCommData.anstext));
            number++;
        }

        req.setAttribute("Index", i);
        req.setAttribute("notresp",not);
        req.getRequestDispatcher("/login/comm/user.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req,resp);
    }
}
